package server.dataaccess;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;
import org.apache.log4j.Logger;

public class Database {
    
    private Connection conn;
    private ResourceBundle bundle;
    private static Database instance = new Database();
    private Logger logger = Logger.getLogger(Database.class);

    private Database() {
        bundle = ResourceBundle.getBundle("server.dataaccess.database");
        loadDatabaseDriver(bundle.getString("driver"));
    }

    private void loadDatabaseDriver(String driver){
        try{
            Class.forName(driver);
        }catch(Exception ex){
            logger.error("Fout bij het laden van de driver!");
            logger.error(ex.getMessage());
        }
    }

    public static Database getInstance(){
        return instance;
    }

    public Connection getConnection() throws SQLException{
        return DriverManager.getConnection(bundle.getString("connectionstring"),
                bundle.getString("user"),bundle.getString("password"));
    }
}
